/*     */ package dm.jdbc.driver;
/*     */ 
/*     */ import dm.jdbc.dataConvertion.CnvtInfo;
/*     */ import dm.jdbc.dataConvertion.Convertion;
/*     */ import dm.jdbc.dbaccess.DBError;
/*     */ import dm.jdbc.dbaccess.DmMsgSend;
/*     */ import dm.jdbc.desc.ParameterDesc;
/*     */ import dm.sql.DmdbDateTime;
/*     */ import dm.sql.DmdbTime;
/*     */ import java.math.BigDecimal;
/*     */ import java.sql.SQLException;
/*     */ 
/*     */ 
/*     */ 
/*     */ public class DmStringBinder
/*     */   extends DmBinder
/*     */ {
/*  18 */   boolean new_lob_flag = false;
/*     */   
/*  20 */   private int m_strRealLen = 0;
/*     */   
/*     */   public DmStringBinder(DmdbPreparedStatement_bs pstmt, int prec)
/*     */   {
/*  24 */     super(pstmt);
/*  25 */     this.m_strRealLen = prec;
/*  26 */     this.new_lob_flag = pstmt.getConnection_bs().getNewLobFlag();
/*     */   }
/*     */   
/*     */   void init()
/*     */   {
/*  31 */     this.recDType = 2;
/*  32 */     this.recPrec = 8188;
/*  33 */     this.recScale = 0;
/*     */   }
/*     */   
/*     */   void checkType(int icol, boolean forBatch) throws SQLException
/*     */   {
/*  38 */     if (this.m_checkType) {
/*  39 */       return;
/*     */     }
/*  41 */     this.m_checkType = true;
/*     */     
/*  43 */     if (this.paramsDesc == null) {
/*  44 */       this.paramsDesc = this.pstmt.getParamsDesc();
/*     */     }
/*  46 */     byte typeFlag = this.paramsDesc[icol].getTypeFlag();
/*  47 */     int dType = this.paramsDesc[icol].getDType();
/*  48 */     int prec = this.paramsDesc[icol].getPrec();
/*  49 */     int scale = this.paramsDesc[icol].getScale();
/*  50 */     byte ioType = this.paramsDesc[icol].getIOType();
/*     */     
/*  52 */     if ((ioType != 1) && (typeFlag != 1))
/*     */     {
/*  54 */       this.destDType = this.recDType;
/*  55 */       this.destPrec = this.recPrec;
/*  56 */       this.destScale = this.recScale;
/*     */       
/*  58 */       if ((!forBatch) && (DmdbType.isNumberType(dType)))
/*     */       {
/*  60 */         this.destPrec = (this.m_strRealLen < 8188 ? this.m_strRealLen : 8188);
/*     */       }
/*  62 */       else if ((!forBatch) && (dType == 2))
/*     */       {
/*  64 */         this.destPrec = (this.m_strRealLen < prec ? prec : this.m_strRealLen);
/*     */       }
/*     */     }
/*     */     else
/*     */     {
/*  69 */       this.destDType = dType;
/*  70 */       this.destPrec = prec;
/*  71 */       this.destScale = scale;
/*     */     }
/*     */     
/*  74 */     this.destIoType = ioType;
/*  75 */     this.srcScale = scale;
/*     */   }
/*     */   
/*     */   public int bindData(DmMsgSend msg, int irow, int icol, boolean forBatch) throws SQLException
/*     */   {
/*  80 */     String x = ((String[])this.pstmt.m_paramObjects[icol])[irow];
/*  81 */     CnvtInfo cnvtInfo = this.pstmt.connection.getCnvtInfo();
/*     */     
/*  83 */     byte[] ret = toDbBytes(x, this.destDType, this.destPrec, this.destScale, cnvtInfo.getServerEncoding(), 
/*  84 */       cnvtInfo.getTimeZone(), cnvtInfo.getDbTz());
/*     */     
/*  86 */     if ((this.destDType == 12) || (this.destDType == 19))
/*     */     {
/*  88 */       if (ret.length > 2048) {
/*  89 */         return -1;
/*     */       }
/*     */     }
/*  92 */     return msg.appendBytesWithLen2(ret, 0, ret.length);
/*     */   }
/*     */   
/*     */   public static byte[] toDbBytes(String x, int destDType, int destPrec, int destScale, String serverEncoding, short ltz, short dtz)
/*     */     throws SQLException
/*     */   {
/*  98 */     byte[] ret = null;
/*     */     
/* 100 */     switch (destDType)
/*     */     {
/*     */     case 0: 
/*     */     case 1: 
/* 104 */       ret = Convertion.String_char_2CType(x, destPrec, destDType, serverEncoding);
/* 105 */       break;
/*     */     case 2: 
/* 107 */       ret = Convertion.String_varchar_2CType(x, destPrec, destDType, serverEncoding);
/* 108 */       break;
/*     */     
/*     */     case 18: 
/* 111 */       ret = Convertion.stringToBinary(x, destPrec);
/*     */       
/* 113 */       break;
/*     */     
/*     */     case 17: 
/* 116 */       ret = Convertion.stringToBinary(x, destPrec);
/*     */       
/* 118 */       break;
/*     */     case 12: 
/* 120 */       ret = Convertion.stringToBinary(x, destPrec);
/* 121 */       break;
/*     */     case 19: 
/* 123 */       ret = Convertion.getBytes(x, serverEncoding);
/* 124 */       break;
/*     */     case 5: 
/* 126 */       ret = Convertion.byteToByteArray(Byte.parseByte(x.trim()));
/* 127 */       break;
/*     */     case 6: 
/* 129 */       ret = Convertion.shortToByteArray(Short.parseShort(x.trim()));
/* 130 */       break;
/*     */     case 7: 
/* 132 */       ret = Convertion.IntToByteArray(Integer.parseInt(x.trim()));
/* 133 */       break;
/*     */     case 8: 
/* 135 */       ret = Convertion.longToByteArray(Long.parseLong(x.trim()));
/* 136 */       break;
/*     */     case 10: 
/* 138 */       ret = Convertion.floatToByteArray(Float.parseFloat(x.trim()));
/* 139 */       break;
/*     */     case 11: 
/* 141 */       ret = Convertion.doubleToByteArray(Double.parseDouble(x.trim()));
/* 142 */       break;
/*     */     case 9: 
/*     */     case 24: 
/* 145 */       ret = Convertion.BigDecimalToByteArray(x, destPrec, destScale);
/* 146 */       break;
/*     */     case 3: 
/*     */     case 13: 
/* 149 */       boolean b = false;
/*     */       
/* 151 */       if (x.equalsIgnoreCase("true"))
/*     */       {
/* 153 */         b = true;
/*     */       }
/* 155 */       else if (x.equalsIgnoreCase("false"))
/*     */       {
/* 157 */         b = false;
/*     */       }
/*     */       else
/*     */       {
/*     */         try
/*     */         {
/* 163 */           if (new BigDecimal(x).compareTo(new BigDecimal(0.0D)) != 0)
/*     */           {
/* 165 */             b = true;
/*     */           }
/*     */         } catch (Exception e) {
/* 168 */           DBError.throwSQLException(6007);
/*     */         }
/*     */       }
/* 171 */       ret = Convertion.booleanToByteArray(b);
/* 172 */       break;
/*     */     
/*     */     case 14: 
/* 175 */       DmdbDateTime dt = new DmdbDateTime(x.trim(), destScale, 0);
/* 176 */       ret = Convertion.DateToByteArray(dt);
/*     */       
/* 178 */       break;
/*     */     
/*     */     case 15: 
/* 181 */       DmdbTime t = new DmdbTime(x.trim(), destScale);
/* 182 */       ret = Convertion.TimeToByteArray(t);
/*     */       
/* 184 */       break;
/*     */     
/*     */     case 16: 
/* 187 */       int[] ts = DmdbDateTime.stringToDT(x.trim(), destDType, destScale, ltz);
/* 188 */       DmdbDateTime dt = new DmdbDateTime(ts, destScale, 2);
/* 189 */       ret = Convertion.TimeStampToByteArray(dt, destDType, destScale, dtz, ltz);
/*     */       
/* 191 */       break;
/*     */     case 20: 
/*     */     case 21: 
/*     */     case 22: 
/*     */     case 23: 
/* 196 */       ret = Convertion.String_javaObj_2CType(x, destDType, destScale, destPrec, ltz);
/* 197 */       break;
/*     */     case 4: default: 
/* 199 */       DBError.throwSQLException(6007);
/*     */     }
/*     */     
/* 202 */     return ret;
/*     */   }
/*     */   
/*     */   public int bindLobCyc(DmMsgSend lobMsg, int irow, int icol)
/*     */     throws SQLException
/*     */   {
/* 208 */     String str = ((String[])this.pstmt.m_paramObjects[icol])[irow];
/* 209 */     String serverEncoding = this.pstmt.connection.getServerEncoding();
/* 210 */     int maxLen = 8000;
/*     */     
/* 212 */     if (this.offset_var >= str.length())
/*     */     {
/* 214 */       clearVars();
/* 215 */       return 0;
/*     */     }
/*     */     
/* 218 */     if (this.offset_var == -1) {
/* 219 */       this.offset_var = 0;
/*     */     }
/* 221 */     int leftLen = str.length() - this.offset_var;
/* 222 */     int readLen = leftLen < maxLen ? leftLen : maxLen;
/* 223 */     int endLen = this.offset_var + readLen;
/* 224 */     String subStr = str.substring(this.offset_var, endLen);
/* 225 */     this.offset_var += readLen;
/*     */     byte[] strbs;
/*     */     byte[] strbs;
/* 228 */     if ((this.destDType == 12) || (this.destDType == 17) || (this.destDType == 18))
/*     */     {
/* 230 */       strbs = Convertion.stringToBinary(subStr, this.destPrec);
/*     */     }
/*     */     else {
/* 233 */       strbs = Convertion.getBytes(subStr, serverEncoding);
/*     */     }
/*     */     
/* 236 */     return lobMsg.appendOffRowBytes(strbs, 0, strbs.length, this.new_lob_flag, subStr.length());
/*     */   }
/*     */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\jdbc\driver\DmStringBinder.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */